package tests;

import jade.core.AID;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;

public class SenderNode extends Agent {
	
	private String[] neigh = new String[1];
	
	protected void setup()
	{
		try
		{
			Object[] args = getArguments();
			neigh[0] = (String) args[0];
			send();
			
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	private void send()
	{
		int i=0;
		
		while (true)
		{
			if (i == 100) return;
			
			ACLMessage msg = createMessage(i++, neigh[0]);
			Q.getInstance().send(this, msg);
		}
	}
	
	private ACLMessage createMessage(int content, String recepient)
	{
		ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
		msg.setContent("" + content);
		msg.addReceiver(new AID(recepient, AID.ISLOCALNAME));
		return msg;
	}
}
